package cn.zysuyuan.item.controller;

import cn.zysuyuan.common.entity.PageResult;
import cn.zysuyuan.common.entity.R;
import cn.zysuyuan.item.entity.Edition;
import cn.zysuyuan.item.service.EditionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-02-17 14:30
 */

@Api(tags = "归档管理")
@RestController
@RequestMapping("edition")
public class EditionController {

    @Autowired
    private EditionService editionService;

    @ApiOperation(value = "归档信息列表管理", notes = "归档信息列表管理")
    @GetMapping("editionData")
    public ResponseEntity<PageResult<Edition>> select(@RequestParam Map<String,Object> map) {
        PageResult<Edition> result = editionService.selectList(map);
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value="对所有数据的归档操作", notes="对所有数据的归档操作")
    @PostMapping("editionData")
    public R saveEdition(@RequestBody Edition edition) {
        editionService.add(edition);
        editionService.saveFile(edition.gettFileEditionId());
        return R.ok();
    }

    @ApiOperation(value="修改信息", notes="修改信息")
    @PutMapping("editionData")
    public R update(@RequestBody Edition edition) {
        editionService.update(edition);
        return R.ok();
    }

    @ApiOperation(value="删除信息", notes="删除信息")
    @DeleteMapping("editionData")
    public R delete(@RequestBody Edition edition) {
        //System.out.println("##################test: time:  "+edition.geteTime());
        editionService.delete(edition);
        return R.ok();
    }

}
